package com.aptemo.webetek.client.widgets.statistics;

import com.aptemo.webetek.client.widgets.CurrencyWidget;
import com.aptemo.webetek.client.widgets.NumberWidget;
import com.aptemo.webetek.shared.LoginBean;
import com.aptemo.webetek.shared.UserBean;
import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;

public class UserStatistics
		extends Composite
{
	private static UserStatisticsUiBinder	uiBinder	= GWT.create(UserStatisticsUiBinder.class);

	interface UserStatisticsUiBinder extends UiBinder<Widget, UserStatistics>
	{
	}

	@UiField
	NumberWidget	placedBets;
	@UiField
	NumberWidget	placedBetsRank;
	@UiField
	NumberWidget	betsWon;
	@UiField
	NumberWidget	betsWonRank;
	@UiField
	NumberWidget	earningsRank;
	@UiField
	NumberWidget	profitability;
	@UiField
	NumberWidget	profitabilityRank;

	// @UiField
	// NumberWidget allBets;
	// @UiField
	// NumberWidget allBetsRank;
	// @UiField
	// NumberWidget activeBets;
	// @UiField
	// NumberWidget activeBetsRank;

	// @UiField
	// NumberWidget teams;

	@UiField
	NumberWidget	success;
	@UiField
	CurrencyWidget	investment;
	@UiField
	CurrencyWidget	earnings;
	// @UiField
	// CurrencyWidget earnings;
	@UiField
	CurrencyWidget	gain;

	// @UiConstructor
	// NumberWidget createSuccess()
	// {
	// return new NumberWidget(NumberFormat.getPercentFormat());
	// }

	public UserStatistics(UserBean stats, LoginBean userbean)
	{
		initWidget(uiBinder.createAndBindUi(this));

		// user.setInnerText(userbean.getEmail());

		// allBets.setValue(stats.getTotalBetCnt());
		// openedBets.setValue(stats.getNoOfActiveBets());

		// allBets.setValue(stats.getNoOfAllBets());
		// activeBets.setValue(stats.getNoOfActiveBets());
		placedBets.setValue(stats.getTotalBetCnt());
		betsWon.setValue(stats.getWonBetCnt());

		// teams.setValue(stats.getNoOfTeams());

		investment.setValue((-1) * stats.getInvestment());
		earnings.setValue(stats.getEarnings());
		// earnings.setValue(stats.getEarnings());
		gain.setValue(stats.getEarnings() - (-1) * stats.getInvestment());

		double s = (0.0 + stats.getWonBetCnt()) / stats.getTotalBetCnt();
		success.setValue(s);
		double p = (0.0 + stats.getEarnings()) / ((-1) * stats.getInvestment());
		profitability.setValue(p);

		// ranks...

	}
}
